package com.controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.util.HandleInfo;
import com.util.Regex;
import com.util.StateInfo;

public class BorrowInsQueryServlet extends HttpServlet
{

	public void doGet(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		String key = request.getParameter("key");
		String value = request.getParameter("value");
		if (null == key || null == value || "".equals(key) || "".equals(value))
		{
			HandleInfo.handle(request, response, StateInfo.INNER_CONFIRM_FAIL);
			return;
		}
		if ("barcode".equals(key))
		{
			if ("".equals(value) || value.length() > 45
					|| !Regex.checkBarcode(value))
			{
				HandleInfo.handle(request, response,
						StateInfo.INNER_CONFIRM_FAIL);
				return;
			}

		}
		if ("insname".equals(key))
		{
			if ("".equals(value))
			{
				HandleInfo.handle(request, response,
						StateInfo.INNER_CONFIRM_FAIL);
				return;
			}
		}
		if ("userid".equals(key))
		{
			if ("".equals(value) || value.length() != 8 || !Regex.checkUserID(value))
			{
				HandleInfo.handle(request, response,
						StateInfo.INNER_CONFIRM_FAIL);
				return;
			}
		}
		if ("firstname".equals(key) || "lastname".equals(key))
		{
			if ("".equals(value) || !Regex.checkName(value))
			{
				HandleInfo.handle(request, response,
						StateInfo.INNER_CONFIRM_FAIL);
				return;
			}
		}
		System.out.println("1");
		String flag = request.getParameter("flag");

		if (null != flag && "date".equals(flag))
		{
			String sDate = request.getParameter("sdate");
			String eDate = request.getParameter("edate");
			if (null == sDate || null == eDate || sDate == "" || eDate == ""
					|| !Regex.checkDate(eDate) || !Regex.checkDate(eDate))
			{
				HandleInfo.handle(request, response,
						StateInfo.INNER_CONFIRM_FAIL);
				return;
			}
			System.out.println("check");
		}
		System.out.println("3");
	}

	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException
	{
		doGet(request, response);
	}

}
